package project.server;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

/**
 * The class ServerLogger. Used for printing different 
 * messages about the servers work to the console and writing to the file.
 * @author Martin
 */
public class GameLogger extends Thread{

	private Logger logger;
	private FileHandler fh;
	
	/**
	 * Instantiates a new ServerLogge
	 * @param logName the name of the logger
	 */

	public GameLogger(String logName) {
		logger = Logger.getLogger(logName);

		try {
			fh = new FileHandler(
					"src//project//gameLog//GameLog.log",
					true);
			logger.addHandler(fh);
			logger.setLevel(Level.ALL);
			SimpleFormatter formatter = new SimpleFormatter();
			fh.setFormatter(formatter);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Method for displaying log messages to the console 
	 * and for writing to the file
	 * @param level the level of the message (Warning,info etc.)
	 * @param message the message that will be logged.
	 */

	public synchronized void log(Level level, String message) {
		logger.log(level, message);
	}
}
